<template>
  <div className="common-field">
    <div className="common-field__content">
      <div class="common-field__content-label">
        <slot name="label">
          <span>{{ label }}</span>
        </slot>
      </div>
      <div
        :class="[
          `position-${contentAlign}`,
          contentEllipsis && 'value-ellipsis',
        ]"
        class="common-field__content-value"
      >
        <slot name="content">
          {{ content }}
        </slot>
      </div>
    </div>
    <div v-if="showArrow" className="common-field__right">
      <slot name="right">
        <image src="@/assets/icon/icon-right@2x.png" />
      </slot>
    </div>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "common-field",
});

export type CommonFieldProps = {
  label?: string;
  content?: string;
  contentAlign?: "left" | "center" | "right";
  contentEllipsis?: boolean;
  showArrow?: boolean;
};

withDefaults(defineProps<CommonFieldProps>(), {
  label: "",
  content: "",
  contentAlign: "right",
  contentEllipsis: true,
  showArrow: true,
});
</script>

<style lang="less">
.common-field {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;
  padding: 20px 0;
  background-color: white;
  &__content {
    width: 0;
    height: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 16px;
    &-label {
      font-weight: 400;
      font-size: 28px;
      color: #000000;
      line-height: 40px;
    }
    &-value {
      width: 0;
      flex: 1;
      font-weight: 400;
      font-size: 28px;
      color: #8b8b8b;
      line-height: 40px;
      display: flex;
      align-items: center;
      &.position-left {
        justify-content: flex-start;
      }
      &.position-center {
        justify-content: center;
      }
      &.position-right {
        justify-content: flex-end;
      }
      &.value-ellipsis {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  &__right {
    image {
      width: 12px;
      height: 24px;
    }
  }
}
</style>
